<?php

namespace Trawind\Events\Subscribers\Finance\Prepayment;

use Trawind\Events\Events\Prepayment\CancelPrepaymentEvent;
use Trawind\Extension\Models\Deploy\BusinessType;

class PrepaymentSubscriber
{
    private $businessType = \Trawind\Basics\Enums\BusinessType::FINANCE_PREPAYMENT;



    public function cancelPrepayment($event)
    {
        if ($this->businessType == $event->payload['business_type_id']) {
            $repository = BusinessType::getEloquentById($this->businessType);
            $repository->callback($event->payload, CancelPrepaymentEvent::class);
        }
    }

    /**
     *
     * @param \Illuminate\Events\Dispatcher $events
     */
    public function subscribe($events)
    {
        $events->listen(
            CancelPrepaymentEvent::class,
            static::class . '@cancelPrepayment'
        );
    }
}